package com.readfeed.app.fragment;
import com.readfeed.app.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;

public class ErrorDialogFragment extends DialogFragment {

	public static ErrorDialogFragment newInstance(int messageId){
		ErrorDialogFragment dialogFragment = new ErrorDialogFragment();
		
		Bundle args = new Bundle();
		args.putInt("message", messageId);
		dialogFragment.setArguments(args);
		
		return dialogFragment;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) { 
		super.onCreate(savedInstanceState);
		setCancelable(false);
	}
	
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
    	Activity activity = getActivity();
		AlertDialog.Builder builder = new AlertDialog.Builder(activity);	
		
		int message = getArguments().getInt("message");		
		builder.setTitle(R.string.error_dialog_title)
			.setIcon(R.drawable.ic_error)
			.setMessage(message)			
			.setPositiveButton(R.string.ok_button, new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					dialog.dismiss();				
				}
			});		
		
		return builder.create();
	}
}
